package fr.upstlse.glre.client.widgets;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;

/**
 * TextField widget représente un champ INPUT de type texte en HTML associé à un label.
 * Le label et le textbox sont disposés horizontalement.
 * @author michael
 *
 */
public class TextField extends Composite {
	private Label label;
	private TextBox textbox;
	private String value;
	
	/**
	 * Construit un champ sans valeur.
	 * 
	 * @param pLabel
	 * @param pName
	 */
	public TextField(String pLabel, String pName) {
		label = new Label(pLabel);
		textbox = new TextBox();
		textbox.setName(pName);
		value = "";
		HorizontalPanel lPanel = new HorizontalPanel();
		lPanel.add(label);
		lPanel.add(textbox);
		initWidget(lPanel);
	}
	
	public TextField(String pLabel, String pName, String pValue) {
		label = new Label(pLabel);
		textbox = new TextBox();
		textbox.setName(pName);
		value = pValue;
		textbox.setText(value);
		HorizontalPanel lPanel = new HorizontalPanel();
		lPanel.add(label);
		lPanel.add(textbox);
		initWidget(lPanel);
	}

	public Label getLabel() {
		return label;
	}

	public void setLabel(Label label) {
		this.label = label;
	}

	public TextBox getTextbox() {
		return textbox;
	}

	public void setTextbox(TextBox textbox) {
		this.textbox = textbox;
	}

	public String getValue() {
		value = textbox.getText();
		return value;
	}

	public void setValue(String pValue) {
		value = pValue;
		textbox.setText(value);
	}

}
